package cn.wolfcode.productserver.web.controller;

import cn.wolfcode.productserver.domain.Product;
import cn.wolfcode.productserver.service.IProductService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author JMJ
 * @date 2021/3/22 14:28
 */
@RestController
@Slf4j
public class ProductController {

    @Autowired
    private IProductService productService;
    @Value("${server.port}")
    private String port;

    @Value("${spring.application.name}")
    private String name;

//    int count = 0;
    @RequestMapping("/product")
    public Product findById(@RequestParam("pid") Long pid) {
//        try {
//            Thread.sleep(900);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        log.info("接下来要进行{}号商品信息的查询", pid);
        Product product = productService.findById(pid);
        product.setPname(product.getPname()+",,port::"+port + ",名字"+name);
//        log.info("商品信息查询成功,内容为{}", JSON.toJSONString(product));

//        log.info("第几次:{}",++count);

        log.info("product------------测试链路追踪");
        return product;
    }
}